package com.yanqu.road.server.cmd.yrank.union;

import com.yanqu.road.entity.union.UnionBaseInfo;
import com.yanqu.road.logic.pb.UnionBasePb;
import com.yanqu.road.logic.pb.YRankPb;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.rank.YRankProto;
import com.yanqu.road.server.cmd.CrossUnionCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.manager.yrank.CrossYRankMgr;
import com.yanqu.road.server.protocol.CrossProtocol;

@Cmd(code = CrossProtocol.C2_CROSS_YRANK_UPLOAD_UNION_RANK_USER, desc = "")
public class CrossYRankUploadUnionRankUserCmd extends CrossUnionCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        YRankProto.UnionYRankUserListMsg listMsg = YRankProto.UnionYRankUserListMsg.parseFrom(packet.getBytes());
        for (YRankProto.UnionYRankUserMsg unionYRankUserMsg : listMsg.getRankListList()) {
            UnionBaseInfo unionBaseInfo = unionYRankUserMsg.hasUnionBaseInfo() ? UnionBasePb.parseUnionBaseInfo(unionYRankUserMsg.getUnionBaseInfo()) : null;
            CrossYRankMgr.unionUserRankChange(
                    YRankPb.parseUserYRank(listMsg.getActivityId(), listMsg.getGroupId(), listMsg.getIdKey(), unionYRankUserMsg.getUser()),
                    unionYRankUserMsg.getUnionUid(),
                    unionBaseInfo,
                    YRankPb.parsePosMap(unionYRankUserMsg.getPosListList()),
                    unionYRankUserMsg.getChangeType()
            );
        }
    }

    @Override
    public void sendData() {

    }
}
